import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] result = new int[2];
        //缓存
        Map<Integer, Integer> cache = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int key = target - nums[i];
            if (cache.containsKey(key)) {
                result[0] = cache.get(key);
                result[1] = i;
                return result;
            }
            cache.put(nums[i], i);
        }
        return result;
    }
}